﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtOfTest.WebAii.Silverlight.UI;
using SM2Utilities;
using SM2Profile;
using ArtOfTest.WebAii.Silverlight;

namespace SM2DashBoard
{
    public class DashBoard
    {
        public static void createDashBoard()
        {
            System.Threading.Thread.Sleep(5000);
            //Prepare data
            string strDBName = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("DashBoard Name");
            string stringChartName = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Chart Name");
            string stringProfile = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Profile Name");
            Boolean blAutoArrange = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Auto Arrange").ToLower().Equals("true") ? true : false;
            Boolean blShare = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Share").ToLower().Equals("true") ? true : false;
            
            //Check dashboard page is loaded
            CommonLoader.load("dashboard.aspx");
            System.Threading.Thread.Sleep(10000);

            //Get Silverlight reference if it doesn't
            try
            {
                SilverlightAppsList slist = Utilities.GlobalObject.MANAGER.ActiveBrowser.SilverlightApps();
                Utilities.GlobalObject.SILVERLIGHTAPP = slist[0];
            }
            catch { Utilities.GlobalObject.SILVERLIGHTAPP = Utilities.GlobalObject.MANAGER.ActiveBrowser.SilverlightApps()[0]; }
            
            //1.
            if (DashboardDialog.verifyDashboardDialogDisplay())
            {
                DashboardDialog.close();
            }
            
            //Click Add Dashboard
            DashboardMainPage.clickAddDashboard();
            System.Threading.Thread.Sleep(4000);

            //Select "Add New Dashboard" this is a new, blank dashboard for you to start addding panels to.
            DashboardCatalogDialog.selectAddNewBlankDashboard();
            System.Threading.Thread.Sleep(2000);

            //2.
            DashboardSettings.setName(strDBName);
            System.Threading.Thread.Sleep(500);
            DashboardSettings.setAutoRange(blAutoArrange);
            System.Threading.Thread.Sleep(500);
            DashboardSettings.setShare(blShare);
            System.Threading.Thread.Sleep(500);
            DashboardSettings.clickOK();
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);

            //3.
            AddPanelsDialog.selectCharts(stringChartName);

            //4.
            AddPanelsDialog.selectProfile(stringProfile);

            //5.
            AddPanelsDialog.clickOK();
            DashboardMainPage.waitForAllPanelsLoaded();
            System.Threading.Thread.Sleep(5000);
        }

        public static void removeDashBoard()
        {
            string strDBName = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("DashBoard Name");
            DashboardMainPage.selectDashboard(strDBName);
            DashboardMainPage.clickRemoveDashboard();
        }

        public static void editDashBoard()
        {
            //Prepare data
            string strDBName = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("DashBoard Name");
            string strNewDBName = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("New DashBoard Name");
            Boolean blAutoArrange = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Auto Arrange").ToLower().Equals("true") ? true : false;
            Boolean blShare = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Share").ToLower().Equals("true") ? true : false;

            DashboardMainPage.selectDashboard(strDBName);
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);
            DashboardMainPage.clickEditDashboard();
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);
            DashboardSettings.setName(strNewDBName);
            System.Threading.Thread.Sleep(500);
            DashboardSettings.setAutoRange(blAutoArrange);
            System.Threading.Thread.Sleep(500);
            DashboardSettings.setShare(blShare);
            System.Threading.Thread.Sleep(500);
            DashboardSettings.clickOK();
            DashboardMainPage.waitForAllPanelsLoaded();
        }

        public static void closeDashBoard()
        {
            DashboardDialog.close();
        }

    }
}
